#encoding:utf8

import os		
import sys
import collections

#######################################################################################
def start_py():
	'''open py directory under help directory'''
	dirpath = r"D:\me\help\py"	  
	os.startfile(dirpath)  

#######################################################################################
def start_library():
	'''open python directory under my library'''
	dirpath = r"D:\me\library\python"	 
	os.startfile(dirpath)  

#######################################################################################
def start_lib():
	'''open python's lib directory'''
	dirpath = os.path.join(sys.prefix, 'Lib')	 
	os.startfile(dirpath)  

#######################################################################################
def start_prefix():
	'''open python's prefix directory'''
	os.startfile(sys.prefix)  

#######################################################################################
def start_site():
	'''open python's site-packages directory'''
	dirpath = os.path.join(sys.prefix, r'Lib\site-packages')	
	os.startfile(dirpath)  

#######################################################################################
class ArgumentDispatcher(object):
	def __init__(self, defautlProcessor):
		assert isinstance(defautlProcessor, collections.Callable)
		self._defautlProcessor		= defautlProcessor

		self._processors			= {}
		self._processors['-h']		= self.usage
		self._processors['--help']	= self.usage

	def add(self, param, processor):
		self._processors[param]	= processor

	def run(self):
		isFind	=  False
		for arg in sys.argv[1:]:
			if arg in self._processors:
				processor	= self._processors[arg]
				print(processor.__doc__)
				processor()
				isFind		= True

		if not isFind:
			print(self._defautlProcessor.__doc__)
			self._defautlProcessor()
	
	def usage(self):
		'''show this help message and exit'''
		keys	= list(self._processors.keys())
		text	= 'usage: %s [%s]\n'%(os.path.basename(sys.argv[0]), '] ['.join(keys))
		arguments	= []
		for k, v in list(self._processors.items()):
			arguments.append('	%-15s%s'%(k, v.__doc__))

		text	= '%s\noptional arguments:\n%s'%(text, '\n'.join(arguments))
		print(text)

def main():
	dispatcher	= ArgumentDispatcher(start_py)
	dispatcher.add('-l', start_library)
	dispatcher.add('--lib', start_lib)
	dispatcher.add('--prefix', start_prefix)
	dispatcher.add('--site', start_site)
	dispatcher.run()

if __name__=='__main__':main()
